package com.hncj.yqfk.console;


import com.hncj.yqfk.utils.PhoneUtil;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * 过滤器，实现拦截功能
 *
 * **/
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response,Object handler) throws Exception {
//        session.getAttribute("ua");
        String ua = request.getHeader("User-Agent");
        Object user = request.getSession().getAttribute("loginUser");
        if (user == null || user.equals(""))  {
            if(PhoneUtil.checkAgentIsMobile(ua)==true){
                response.sendRedirect("/login/mlogin.html");
            }
            else{
                response.sendRedirect("/login/login.html");
            }
            return false;
        }
        return true;
    }
}


